<template>
  <el-dialog
    :append-to-body="true"
    @close="closeDialog"
    :visible.sync="dialog"
    :title="is_edit?'编辑工作流':'添加工作流'"
    width="500px"
  >
    <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
      <el-form-item label="名称" prop="name">
        <el-input placeholder="输入工作流名称" v-model="form.name" style="width: 320px;" maxlength="20" />
      </el-form-item>
      <el-form-item label="工单类型" prop="orderCategoryId">
        <el-select v-model="form.orderCategoryId" placeholder="请选择工单类型" style="width: 320px;">
          <el-option v-for="item in dept_list" :key="item.id" :label="item.name" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="组织机构" prop="deptId">
        <treeselect
          v-model="form.deptId"
          :options="menus"
          style="width: 320px;"
          placeholder="选择所属行业"
        />
      </el-form-item>-->
      <el-form-item label="状态" prop="status" v-if="0">
        <el-radio-group v-model="form.enabled">
          <el-radio
            v-for="item in [{id:1,value:true,lable:'启用'}, {id:2,value:false,lable:'禁用'}]"
            :key="item.id"
            :label="item.value"
          >{{item.lable}}</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="流程简介">
        <!-- <img style="width: 340px;" src="@/assets/workflow.png" alt /> -->
        <div class="el-steps fz12 el-steps--horizontal">
          <div class="el-step is-horizontal" style="flex-basis: 25%; margin-right: 0px;">
            <div class="el-step__head is-wait">
              <div class="el-step__line" style="margin-right: 0px;">
                <i
                  class="el-step__line-inner"
                  style="transition-delay: 0ms; border-width: 0px; width: 0%;"
                ></i>
              </div>
              <div class="el-step__icon is-text">
                <!---->
                <div class="el-step__icon-inner">1</div>
              </div>
            </div>
            <div class="el-step__main">
              <div class="el-step__title is-wait" style="font-size:14px;">发起申请</div>
              <div class="el-step__description is-wait"></div>
            </div>
          </div>
          <div class="el-step is-horizontal" style="flex-basis: 25%; margin-right: 0px;">
            <div class="el-step__head is-wait">
              <div class="el-step__line" style="margin-right: 0px;">
                <i
                  class="el-step__line-inner"
                  style="transition-delay: -150ms; border-width: 0px; width: 0%;"
                ></i>
              </div>
              <div class="el-step__icon is-text">
                <!---->
                <div class="el-step__icon-inner">2</div>
              </div>
            </div>
            <div class="el-step__main">
              <div class="el-step__title is-wait" style="font-size:14px;">确认派单</div>
              <div class="el-step__description is-wait"></div>
            </div>
          </div>
          <div class="el-step is-horizontal" style="flex-basis: 25%; margin-right: 0px;">
            <div class="el-step__head is-wait">
              <div class="el-step__line" style="margin-right: 0px;">
                <i
                  class="el-step__line-inner"
                  style="transition-delay: -300ms; border-width: 0px; width: 0%;"
                ></i>
              </div>
              <div class="el-step__icon is-text">
                <!---->
                <div class="el-step__icon-inner">3</div>
              </div>
            </div>
            <div class="el-step__main">
              <div class="el-step__title is-wait" style="font-size:14px;">技术上门</div>
              <div class="el-step__description is-wait"></div>
            </div>
          </div>
          <div class="el-step is-horizontal" style="flex-basis: 25%; max-width: 25%;">
            <div class="el-step__head is-wait">
              <div class="el-step__line">
                <i class="el-step__line-inner"></i>
              </div>
              <div class="el-step__icon is-text">
                <!---->
                <div class="el-step__icon-inner">4</div>
              </div>
            </div>
            <div class="el-step__main">
              <div class="el-step__title is-wait" style="font-size:14px;">服务完成</div>
              <div class="el-step__description is-wait"></div>
            </div>
          </div>
        </div>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button :loading="loading" size="mini" type="primary" @click="doSubmit">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {
  _workflowsCreate,
  _workflowsUpdate,
  _deptList,
  _orderCategoryAll
} from "@/http/ajax";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
  components: { Treeselect },
  name: "edit",
  props: {
    is_edit: {
      type: Boolean,
      required: true
    },
    cur_this: {
      type: Object,
      required: null
    }
  },
  data() {
    return {
      menus: [],
      dialog: false,
      loading: false,
      form: {
        name: "",
        // deptId: 0,
        orderCategoryId: "",
        enabled: true
      },
      dept_list: [],
      rules: {
        name: [
          { required: true, message: "请输入工作流名称", trigger: "blur" }
        ],
        orderCategoryId: [{ required: true, message: "请选择工单类型", trigger: "change" }],
        deptId: [
          { required: true, message: "请选择所属行业", trigger: "change" }
        ]
      }
    };
  },
  created() {},
  methods: {
    doSubmit() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.dialog = true;
          if( !this.form.name.replace(/(^\s*)|(\s*$)/g, "")){
            this.$message({
              message: "工作流名称不能为空",
              type: "error"
            });
            return
          }
          if (this.is_edit) {
            _workflowsUpdate(
              this.form,
              res => {
                this.dialog = false;
                this.cur_this.getList();
                this.dataInit();
                this.$message({
                  message: "操作成功",
                  type: "success"
                });
              },
              err => {}
            );
          } else {
            _workflowsCreate(
              this.form,
              res => {
                this.$message({
                  message: "操作成功",
                  type: "success"
                });
                this.dialog = false;
                this.cur_this.getList();
                this.dataInit();
              },
              err => {}
            );
          }
        }
      });
    },
    domInit() {
      this.getMenus();
    },
    dataInit() {
      this.form = {
        name: "",
        orderCategoryId: 0
      };
    },
    getMenus(file, fileList) {
      // _deptList(
      //   {},
      //   res => {
      //     this.menus = [];
      //     const menu = { id: 0, label: "顶级类目", children: [] };
      //     // let arr = [];
      //     // res.forEach(e => {
      //     //   arr.push({ id: e.id, label: e.name });
      //     // });
      //     menu.children = res.content;
      //     this.menus.push(menu);
      //     console.log(this.menus);
      //   },
      //   err => {}
      // );
      _orderCategoryAll(
        res => {
          this.dept_list = [];
          this.dept_list = res;
        },
        err => {}
      );
    },
    closeDialog() {this.$refs["form"].resetFields();}
  }
};
</script>

<style lang="scss">
</style>
